
#ifndef SWE_MESH
#define SWE_MESH

#include <vector>

#include <swegl/projection/Vec3f.h>
#include <swegl/projection/Vec2f.h>
#include <swegl/Projection/Matrix4x4.h>
#include <swegl/data/Texture.h>

namespace swegl
{

	class Mesh;

	class Strip
	{
	public:
		inline Strip(std::vector<unsigned int> && i, std::vector<Vec2f> && v)
			:m_indexbuffer(i),
			m_texturebuffer(v)
		{}

	public:
		std::vector<unsigned int> m_indexbuffer;
		std::vector<Vec2f> m_texturebuffer;
	};


	class Mesh
	{
	public:
		std::vector<Vec3f> m_vertexbuffer;
		//unsigned int m_vertexcount;
		Matrix4x4 m_worldmatrix;
		Texture *m_texture;
		Texture *m_bumpmap;

		std::vector<Strip> m_strips;          // array of index buffers (triangle strips)
		//unsigned int m_stripcount; // number of strips
		std::vector<Vec3f> m_stripnorms;          // 1 normal per triangle in strips
		//unsigned int m_striptricount; // number of triangles in strips

		std::vector<Strip> m_fans;            // array of index buffers (triangle strips)
		//unsigned int m_fancount;   // number of fans
		std::vector<Vec3f> m_fannorms;            // 1 normal per triangle in strips
		//unsigned int m_fantricount;   // number of triangles in fans

		// 3 neighbours per triangle
		// Indices are triangles in m_stripnorms and m_fannorms
		// Indices consider m_stripnorms and m_fannorms as one array: if i>m_striptricount,
		// i -= m_striptricount, effectively becoming an index in m_fantricount
		//std::vector<unsigned int> m_stripneighbours;
		//std::vector<unsigned int> m_fanneighbours;

		Mesh();
		//void SetVertexBuffer(Vec3f *v, unsigned int count);
		void SetVertexBuffer(std::vector<Vec3f> && v);
		void SetTexture(Texture *t);
		//void AddStrip(unsigned int *indexbuffer, Vec2f *texturebuffer, unsigned int indexcount);
		//void AddFan(unsigned int *indexbuffer, Vec2f *texturebuffer, unsigned int indexcount);
		void AddStrip(std::vector<unsigned int> && indexbuffer, std::vector<Vec2f> && texturebuffer);
		void AddFan(std::vector<unsigned int> && indexbuffer, std::vector<Vec2f> && texturebuffer);
		void SetBumpMap(Texture *t);
		void Prepare();
		//unsigned int FindNeighbour(unsigned int vindex1, unsigned int vindex2, unsigned int triangle);
	};

}

#endif SWE_MESH
